package org.xin.framework.base.pojo.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.*;
import lombok.experimental.Accessors;
import lombok.experimental.SuperBuilder;
import org.hibernate.validator.constraints.Length;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import java.io.Serializable;

/**
 * @author ：xin
 * @date ：Created in 2021/7/14 18:34
 * @description：基础实体
 * @modified By：superlong
 * @version: 1.0$
 */
@Getter
@Setter
@ToString
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
//作为实体父类要让子类拥有自己的属性（数据库表中），需要加此注解
//@MappedSuperclass
public class IBaseEntity implements Serializable {
    private static final long serialVersionUID = 19990927L;

    @TableField("id")
    @TableId(type = IdType.UUID)
    protected String id;

    @TableField(fill = FieldFill.INSERT)
    @CreatedDate
//    protected Date createTime;
    protected String createTime;

    @TableField(fill = FieldFill.UPDATE)
    @LastModifiedDate
//    protected Date  updateTime;
    protected String  updateTime;

    /**
     * @TableLogic 逻辑删除
     */
    @JsonIgnore
    @TableLogic(value = "0", delval = "1")
    protected Boolean isDelete;

    @Length(max = 128, min = 3, message = "备注长度应不超过128个字符")
    protected String remarks;

    @JsonIgnore
    @TableField(update = "%s+1")
    @Version
    protected Integer version;

    @TableField(fill = FieldFill.INSERT)
    @CreatedBy
    protected String createBy;

    @TableField(fill = FieldFill.UPDATE)
    @LastModifiedBy
    protected String updateBy;
}
